using Microsoft.Phone.Shell;
using System;
using System.Windows.Threading;
namespace MicroMsg.UI.UserContrl
{
	public class ScreenLockService
	{
		private const string TAG = "ScreenLockService";
		public static IsMediaPlaying checkMusicPlaying = null;
		private static DispatcherTimer Timer;
		private static bool isInit = false;
		public static void Resume()
		{
			PhoneApplicationService.get_Current().set_UserIdleDetectionMode(0);
		}
		public static void Awake()
		{
			ScreenLockService.Init();
			PhoneApplicationService.get_Current().set_UserIdleDetectionMode(1);
			ScreenLockService.Timer.Stop();
			ScreenLockService.Timer.Start();
		}
		private static void Init()
		{
			if (ScreenLockService.isInit)
			{
				return;
			}
			ScreenLockService.Timer = new DispatcherTimer();
			ScreenLockService.Timer.add_Tick(new EventHandler(ScreenLockService.Timer_Tick));
			ScreenLockService.Timer.set_Interval(new TimeSpan(0, 0, 0, 70));
			ScreenLockService.isInit = true;
		}
		private static void Timer_Tick(object sender, EventArgs e)
		{
			if (ScreenLockService.checkMusicPlaying != null)
			{
				if (!ScreenLockService.checkMusicPlaying())
				{
					ScreenLockService.Resume();
					ScreenLockService.Timer.Stop();
					ScreenLockService.checkMusicPlaying = null;
					return;
				}
			}
			else
			{
				ScreenLockService.Resume();
				ScreenLockService.Timer.Stop();
			}
		}
	}
}
